package com.example.joblinker.service.impl;

import com.example.joblinker.entity.Resume;
import com.example.joblinker.mapper.ResumeMapper;
import com.example.joblinker.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ResumeServiceImpl implements ResumeService {

    @Autowired
    private ResumeMapper resumeMapper;

    @Override
    public List<Resume> getResumeList(Long userId) {
        return resumeMapper.findByUserId(userId);
    }

    @Override
    public Resume getResumeDetail(Long id, Long userId) {
        return resumeMapper.findByIdAndUserId(id, userId);
    }

    @Override
    public Resume getResumeById(Long id) {
        return resumeMapper.selectById(id);
    }

    @Override
    public Resume createResume(Resume resume) {
        resumeMapper.insert(resume);
        return resume;
    }

    @Override
    public boolean updateResume(Resume resume) {
        return resumeMapper.update(resume) > 0;
    }

    @Override
    public boolean deleteResume(Long id, Long userId) {
        return resumeMapper.delete(id, userId) > 0;
    }

    @Override
    @Transactional
    public boolean setDefaultResume(Long id, Long userId) {
        // 先将用户所有简历设置为非默认
        resumeMapper.resetDefaultResumeByUserId(userId);
        // 再将指定简历设置为默认
        return resumeMapper.setDefaultResume(id, userId) > 0;
    }
} 